import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { SFSchema } from '@delon/form';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';

@Component({
  selector: 'app-btn-edit',
  templateUrl: './btn-edit.component.html',
  styles: []
})
export class BtnEditComponent implements OnInit {
  @ViewChild('st', {static: false})st: TablePageComponent;
  @Input()
  set param(value) {
    this.config.defaultParam = {
      menuParentId: value.id,
      menuType: 3
    }
  };
  showEdit = false;
  config: SPage = {
    columns: [
      {
        index: 'id',
        title: '',
        type: ColumnType.checkbox,
      },
      {
        index: 'menuPermit',
        title: '按钮编号',
      },
      {
        index: 'menuName',
        title: '按钮名称'
      },
    ],
    editBtn: [
      {title: '编辑'}
    ],
    reqUrl: this.api.menu.page.url,
    defaultParam: {
      menuType: '3'
    }
  };
  schema: SFSchema = {
    properties: {
      bh: {
        type: 'string',
        title: '按钮编号'
      },
      name: {
        type: 'string',
        title: '按钮名称'
      }
    },
    required: ['bh', 'name']
  };
  btnData: {bh:string, name: string, id?:string, [key: string]: any};
  selectedData: any;
  operate(e): void{
    if (e.title === '编辑') {
      this.btnData = e.data;
      this.showEdit = true;
    }
  }
  delete(): void {
    if (!this.selectedData || this.selectedData.length === 0) {
      this.msg.warning('请选择数据后操作');
      return;
    }
    this.modal.confirm({
      nzTitle: '您确定要删除这些数据吗',
      nzOnOk: () => {
        this.msg.success('删除成功');
        this.st.reload();
      }
    })
  }
  constructor(
    private msg: NzMessageService,
    private modal: NzModalService,
    private api: ApiService
  ) { }

  ngOnInit() {
  }

}
